﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using DotNet.WinUI.Admin;

namespace DotNet.WinUI
{
    public partial class FrmMain : BaseForm
    {
        public FrmMain()
        {
            InitializeComponent();
        }

        private string _LoginID;
        public string LoginID
        {
            get { return _LoginID; }
            set { _LoginID = value; }
        }

        private void FrmMain_Load(object sender, EventArgs e)
        {
            ShowLoginDlg();
        }

        private void ShowLoginDlg()
        {
            FrmLogin objFrmLogin = new FrmLogin();
            if (objFrmLogin.ShowDialog() != System.Windows.Forms.DialogResult.OK)
            {
                Close();

                return;
            }
            LoginID = objFrmLogin._LoginID;
            stbLoingInfo.Text = string.Format("  欢迎 {0} 【 {1} 】 登录系统，登录时间：{2}", LoginID, GetUsersName(LoginID), DateTime.Now);
        }

        private void FrmMain_FormClosing(object sender, FormClosingEventArgs e)
        {
            if (ShowQuestionMsg("确认退出系统?") != DialogResult.OK)
            {
                e.Cancel = true;
                if (string.IsNullOrEmpty(LoginID))
                {
                    ShowLoginDlg();
                }
            }
        }

        private void ShowForm(Form objForm)
        {
            objForm.TopLevel = false;
            objForm.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
            objForm.ControlBox = false;
            objForm.WindowState = FormWindowState.Maximized;
            objForm.StartPosition = FormStartPosition.CenterParent;
            objForm.Dock = DockStyle.Fill;
            pnContainer.Dock = DockStyle.Fill;
            pnContainer.Controls.Clear();
            pnContainer.Controls.Add(objForm);
            objForm.Show();

        }

        private void tsMain_ItemClicked(object sender, ToolStripItemClickedEventArgs e)
        {
            switch (e.ClickedItem.Text)
            {
                case "用户管理":
                    ShowForm(new FrmUsersList());
                    break;
                case "重新登录":
                    LoginID = "";
                    ShowLoginDlg();
                    break;
                case "修改密码":
                    ShowForm(new FrmModPwd(LoginID));
                    break;
                case "退出系统":
                    Close();
                    break;
                default:
                    ShowMsg("此功能暂未实现！");
                    break;
            }
        }
    }
}
